/**
 *WeiboAdapter.java
 *2011-9-29 下午08:18:26
 *Touch Android
 *http://bbs.droidstouch.com
 */
package com.cuit.xsc.weishare.adapter;

import java.util.List;


import com.cuit.xsc.weishare.R;
import com.cuit.xsc.weishare.model.Statuse;
import com.cuit.xsc.weishare.util.TextUtil;
import com.cuit.xsc.weishare.widget.RemoteCacheImageView;
import com.cuit.xsc.weishare.widget.RemoteImageView;


import weibo4android.Status;
import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * @author <a href="http://bbs.droidstouch.com">Touch Android</a>
 *
 */
public class WeiboAdapter extends ArrayListAdapter<Statuse>
{

	private Context context;
	
	public WeiboAdapter(Activity context)
	{
		super(context);
		this.context = context;
	}
	

	public View getView(int position, View convertView, ViewGroup parent)
	{

		// View view = convertView;
		WeiboHolder holder = null;

		if (null == convertView)
		{

			holder = new WeiboHolder();

			convertView = LayoutInflater.from(context).inflate(R.layout.wb_item_template, null);
			holder.img_wb_item_head = (RemoteCacheImageView) convertView.findViewById(R.id.img_wb_item_head);
			holder.txt_wb_item_uname = (TextView) convertView.findViewById(R.id.txt_wb_item_uname);
			holder.txt_wb_item_content = (TextView) convertView.findViewById(R.id.txt_wb_item_content);
			// holder.img_wb_item_content_pic = (RemoteImageView)
			// view.findViewById(R.id.img_wb_item_content_pic);
			holder.txt_wb_item_time = (TextView) convertView.findViewById(R.id.txt_wb_item_time);
			holder.txt_wb_item_from = (TextView) convertView.findViewById(R.id.txt_wb_item_from);
			holder.txt_wb_item_from.setMovementMethod(LinkMovementMethod.getInstance());
			holder.img_wb_item_V = (ImageView) convertView.findViewById(R.id.img_wb_item_V);
			holder.img_wb_item_content_pic = (RemoteImageView) convertView.findViewById(R.id.img_wb_item_content_pic);
			holder.lyt_wb_item_sublayout = (LinearLayout) convertView.findViewById(R.id.lyt_wb_item_sublayout);
			holder.img_wb_item_content_subpic = (RemoteImageView) convertView.findViewById(R.id.img_wb_item_content_subpic);
			holder.txt_wb_item_subcontent = (TextView) convertView.findViewById(R.id.txt_wb_item_subcontent);
			convertView.setTag(holder);
		}
		else
		{
			holder = (WeiboHolder) convertView.getTag();
		}
		Statuse s = mList.get(position);
		holder.img_wb_item_head.setImageUrl(s.getHead(), position, mListView);
		holder.txt_wb_item_uname.setText(s.getuName());
		holder.txt_wb_item_content.setText(Html.fromHtml(s.getContent()));
		holder.txt_wb_item_from.setText("来自:" + Html.fromHtml(s.getFrom()));

		// 判断是否通过认证
		if (s.isVerified())
		{
			holder.img_wb_item_V.setVisibility(View.VISIBLE);
		}
		else
		{
			holder.img_wb_item_V.setVisibility(View.INVISIBLE);
		}

		// 判断微博中是否含有图片
		if (!TextUtil.isEmpty(s.getContent_pic()))
		{
			holder.img_wb_item_content_pic.setVisibility(View.VISIBLE);
			holder.img_wb_item_content_pic.setImageUrl(s.getContent_pic(),position, mListView);
		}
		else
		{
			holder.img_wb_item_content_pic.setVisibility(View.GONE);
		}

		// 判断使用又转发
		if (s.getStatuse() != null)
		{
			holder.lyt_wb_item_sublayout.setVisibility(View.VISIBLE);
			holder.txt_wb_item_subcontent.setText(Html.fromHtml(s.getStatuse().getContent()));

			// 判断微博中是否含有图片
			if (!TextUtil.isEmpty(s.getStatuse().getContent_pic()))
			{
				holder.img_wb_item_content_subpic.setVisibility(View.VISIBLE);
				holder.img_wb_item_content_subpic.setImageUrl(s.getStatuse().getContent_pic(), position, mListView);
			}
			else
			{
				holder.img_wb_item_content_subpic.setVisibility(View.GONE);
			}

		}
		else
		{
			holder.lyt_wb_item_sublayout.setVisibility(View.GONE);
			holder.img_wb_item_content_subpic.setVisibility(View.GONE);
		}

		return convertView;
	}

	
	public class WeiboHolder
	{
		
		RemoteCacheImageView img_wb_item_head;
		
		TextView txt_wb_item_uname;
		
		ImageView img_wb_item_V;
		
		TextView txt_wb_item_time;
		
		TextView txt_wb_item_content;
		
		RemoteImageView img_wb_item_content_pic;
		
		
		
		LinearLayout lyt_wb_item_sublayout;
		
		TextView txt_wb_item_subcontent;
		
		RemoteImageView img_wb_item_content_subpic;
		
		TextView txt_wb_item_from;
		
		TextView txt_wb_item_redirect; //转发数
		
		TextView txt_wb_item_comment; //点评数
		
	}
	
	
	
}
